#pragma once

#include "Types.h"
#include "DLL.h"
#include "BrushTool.h"
#include "FillTool.h"

#include <MyViews/ZoomBench.h>
#include <MyFC/Event.h>

namespace My {

class MaskOwner {
public:
	virtual const BitMask & GetMask() const = 0;
	virtual void SetMask(const BitMask &, const String & action = String()) = 0;
};

class DLL_API MaskEditor : 
	public CCmdTarget,
	public EventDispatcher {
public:
	class Event : public My::Event {
	public:
		MaskEditor &	m_Editor;
		Event(MaskEditor & e) : m_Editor(e) { }
	};
	class MaskChange : public Event {
	public:
		MaskChange(MaskEditor & e) : Event(e) { }
	};
	class StateChange : public Event {
	public:
		StateChange(MaskEditor & e) : Event(e) { }
	};
public:
	MaskEditor(ZoomBench &);
	~MaskEditor();
public:
	ZoomBench & GetBench();
	MaskOwner * GetMaskOwner() const;
	const BitMask & GetBuffer() const;
	BitMask & GetBuffer();
	bool IsOpen() const;
	Extent GetDim() const;
	BrushTool * Brush() const;
	FillTool * Fill() const;
public:
	void Open(MaskOwner &);
	void Close();
	void Synchronize(const String & action);
	void UpdateBuffer();
	/// \return true if the editor is open and translation was successful
	/// bool TranslateAccelerator(MSG * pMsg);
private:
	ZoomBench &		m_Bench;
	MaskOwner *		m_pOwner;
	BitMask			m_Buffer;
	BrushTool		m_Brush;
	FillTool		m_Fill;
	//HACCEL		m_AcceleratorTable;
	bool			m_Sync; ///< this variable is true during Syncronize() operation
	Tool *			m_pTool;
protected:
	DECLARE_MESSAGE_MAP()
public:
	void OnToolBrush();
	void OnUpdateToolBrush(CCmdUI * pCmdUI);
	void OnToolFill();
	void OnUpdateToolFill(CCmdUI * pCmdUI);
	void OnImportMask();
	void OnUpdateImportMask(CCmdUI * pCmdUI);
	void OnExportMask();
	void OnUpdateExportMask(CCmdUI * pCmdUI);
};

} // My

#include "Impl/MaskEditor.inl"
